<template>
	<view class="showPopup">
		<view class="content-box">
			<view class="text-centent">
				请授权后才能继续使用!
				<image src="https://yuyitang.oss-cn-shenzhen.aliyuncs.com/yytfile/user/photo/Saly-16.png" style="width: 80%; height: 80%;"></image>
			</view>
			<u-button type="success" @click="wxRegister" text="微信注册">授 权 登 录</u-button>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		name: "authShowModel",
		computed: {
			...mapState(['applicationConfig', 'session_key', 'openid', 'token'])
		},
		data() {
			return {
				
			}
		},
		methods: {
			wxRegister() {
				const that = this
				uni.getUserProfile({
					desc: "获取你的昵称、头像、地区及性别",
					success: (res) => {
						console.log(res);
						uni.showLoading({
							//title: '加载中'
						});
						this.$api.request.userLoginOrAdd({
							encryptedData: res.encryptedData,
							iv: res.iv,
							sessionKey: this.session_key,
							wechatId: uni.getStorageSync('openId'),
							sourceType: "APP",
							nickName: res.userInfo.nickName,
							avatarUrl: res.userInfo.avatarUrl
						}, resp => {							
							console.log(resp);
							uni.hideLoading();
							if (resp.code == 200) {
								this.$store.commit("setToken", resp.data.tokenValue)
								this.$store.commit("login", resp.data);
								uni.setStorageSync('authStatus', true)
								this.$api.request.userInfo({},res => {
									if(res.code == 200){
										uni.setStorageSync('userInfo', res.data)
										uni.navigateBack({
											delta: 1
										})
									}
								})								
								
							}
						})
					}
				})
			},
		}
	}
</script>

<style>
	.showPopup {
		width: 100vw;
		height: 100vh;
		position: fixed;
		display: flex;
		justify-content: center;
		/* align-items: center; */
		top: 0;
		left: 0;
		background: rgba(0, 0, 0, 0.6);
		z-index: 999 !important;
	}

	.content-box {
		width: 70vw;
		height: 550rpx;
		margin-top: 30vh;
		background: #FFFFFF;
		border-radius: 10rpx;
		display: flex;
		flex-direction: column;
	}

	.text-centent {
		width: 100%;
		height: calc(100% - 80rpx);
		text-align: center;
		padding-top: 20rpx;
	}
</style>
